package com.city.api;

import com.city.config.Code;
import com.city.domain.pub.PubUser;
import com.city.domain.report.CtUser;
import com.city.helper.AuthHelper;
import com.city.repository.report.CtUserRepository;
import com.city.service.report.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @deprecation 公共接口[不需要请求控制]
 * @email leichuqiao@126.com
 * @author 雷楚桥
 * @date 2018-09-02 11:03
 */
@RestController
@RequestMapping("/api/pub")
public class PubApi {

    @Autowired
    private AuthHelper authH;
    @Autowired
    private UserService userS;
    @Autowired
    private CtUserRepository ctUserRepository;

    /**
     * @deprecation 获取用户的基本信息
     * @param sign String 签名
     * @return Map
     * @author 雷楚桥
     * @date 2018-09-02 11:04
     */
    @ResponseBody
    @RequestMapping("/getUserInfo")
    public Map<String,Object> getUserInfo(@Param("sign") String sign){
        Map<String,Object> map = new HashMap<>();
        Integer userId = authH.checkSign(sign);
        if(userId == null){
            map.put("code", Code.SIGN_ERROR);
            map.put("msg", "签名错误");
        }else{
            System.out.println(userId+"========================");
            CtUser user = ctUserRepository.findOne(userId);
            if(user == null){
                map.put("code", Code.FIND_DATA_FEILD);
                map.put("msg", "请求数据失败");
            }else{
                map.put("code", Code.SUCCESS);
                map.put("msg", "请求成功");
                Map<String,Object> data = new HashMap<>();
                data.put("name",user.getName());
                map.put("data",data);
            }
        }
        return map;
    }
}
